﻿using ShareCode.Util.Helper;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace ClientAppraise.Converters;

internal class IntToDateConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == default)
        {
            return DateTime.Now;
        }

        if (!int.TryParse(value.ToString(), out var TypeValue))
        {
            return DateTime.Now;
        }

        if (TypeValue == 0)
        {
            return DateTime.Now;
        }

        return DateTimeHelper.ConvertInt2Datetime(TypeValue);
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == default)
        {
            return 0;
        }

        if (!DateTime.TryParse(value.ToString(),out var TypeValue))
        {
            return 0;
        }

        return DateTimeHelper.ConvertDateTime2Int(TypeValue);
    }
}
